home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BKISSSRC.ZIP / TITLE / MODEX.INC < prev    next >
Encoding:
Text File  |  1994-02-10  |  20.8 KB  |  724 lines

  1. LABEL X320Y200 word
  2.     db      00      ; 0e3h    ; dot clock
  3.     db      02      ; Number of CRTC Registers to update
  4.     dw      00014h  ; turn off dword mode
  5.     dw      0e317h  ; turn on byte mode
  6.     dw      320     ; width
  7.     dw      200     ; height
  8.  
  9. LABEL X320Y200s word
  10.     db      0e3h    ; dot clock
  11.     db      02      ; Number of CRTC Registers to update
  12.     dw      00014h  ; turn off dword mode
  13.     dw      0e317h  ; turn on byte mode
  14.     dw      320     ; width
  15.     dw      200     ; height
  16.  
  17. LABEL X320Y240 word
  18.     db      0e3h    ; dot clock
  19.     db      10      ; Number of CRTC Registers to update
  20.     dw      00d06h  ; vertical total
  21.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  22.     dw      04109h  ; cell height (2 to double-scan)
  23.     dw      0ea10h  ; v sync start
  24.     dw      0ac11h  ; v sync end and protect cr0-cr7
  25.     dw      0df12h  ; vertical displayed
  26.     dw      00014h  ; turn off dword mode
  27.     dw      0e715h  ; v blank start
  28.     dw      00616h  ; v blank end
  29.     dw      0e317h  ; turn on byte mode
  30.     dw      320     ; width
  31.     dw      240     ; height
  32.  
  33. LABEL X360Y200 word
  34.     db      0e7h    ; dot clock
  35.     db      08      ; Number of CRTC Registers to update
  36.     dw      06b00h  ; horz total
  37.     dw      05901h  ; horz displayed
  38.     dw      05a02h  ; start horz blanking
  39.     dw      08e03h  ; end horz blanking
  40.     dw      05e04h  ; start h sync
  41.     dw      08a05h  ; end h sync
  42.     dw      00014h  ; turn off dword mode
  43.     dw      0e317h  ; turn on byte mode
  44.     dw      360     ; width
  45.     dw      200     ; height
  46.  
  47. LABEL X360Y240 word
  48.     db      0e7h    ; dot clock
  49.     db      16      ; Number of CRTC Registers to update
  50.     dw      06b00h  ; horz total
  51.     dw      05901h  ; horz displayed
  52.     dw      05a02h  ; start horz blanking
  53.     dw      08e03h  ; end horz blanking
  54.     dw      05e04h  ; start h sync
  55.     dw      08a05h  ; end h sync
  56.     dw      00d06h  ; vertical total
  57.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  58.     dw      04109h  ; cell height (2 to double-scan)
  59.     dw      0ea10h  ; v sync start
  60.     dw      0ac11h  ; v sync end and protect cr0-cr7
  61.     dw      0df12h  ; vertical displayed
  62.     dw      00014h  ; turn off dword mode
  63.     dw      0e715h  ; v blank start
  64.     dw      00616h  ; v blank end
  65.     dw      0e317h  ; turn on byte mode
  66.     dw      360
  67.     dw      240
  68.  
  69. LABEL X376Y282 word
  70.     db      0e7h
  71.     db      18
  72.     dw      06e00h  ; horz total
  73.     dw      05d01h  ; horz displayed
  74.     dw      05e02h  ; start horz blanking
  75.     dw      09103h  ; end horz blanking
  76.     dw      06204h  ; start h sync
  77.     dw      08f05h  ; end h sync
  78.     dw      06206h  ; vertical total
  79.     dw      0f007h  ; overflow
  80.     dw      06109h  ; cell height
  81.     dw      0310fh  ;
  82.     dw      03710h  ; v sync start
  83.     dw      08911h  ; v sync end and protect cr0-cr7
  84.     dw      03312h  ; vertical displayed
  85.     dw      02f13h  ; offset
  86.     dw      00014h  ; turn off dword mode
  87.     dw      03c15h  ; v blank start
  88.     dw      05c16h  ; v blank end
  89.     dw      0e317h  ; turn on byte mode
  90.     dw      376
  91.     dw      564
  92.  
  93. LABEL X320Y400 word
  94.     db      00      ;0e3h    ; dot clock
  95.     db      03      ; Number of CRTC Registers to update
  96.     dw      04009h  ; cell height
  97.     dw      00014h  ; turn off dword mode
  98.     dw      0e317h  ; turn on byte mode
  99.     dw      320     ; width
  100.     dw      400     ; height
  101.  
  102. LABEL X320Y480 word
  103.     db      0e3h    ; dotclock
  104.     db      10      ; Number of CRTC Registers to update
  105.     dw      00d06h  ; vertical total
  106.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  107.     dw      04009h  ; cell height (2 to double-scan)
  108.     dw      0ea10h  ; v sync start
  109.     dw      0ac11h  ; v sync end and protect cr0-cr7
  110.     dw      0df12h  ; vertical displayed
  111.     dw      00014h  ; turn off dword mode
  112.     dw      0e715h  ; v blank start
  113.     dw      00616h  ; v blank end
  114.     dw      0e317h  ; turn on byte mode
  115.     dw      320     ; width
  116.     dw      480     ; height
  117.  
  118. LABEL X360Y400 word
  119.     db      0e7h    ; dot clock
  120.     db      09      ; Number of CRTC Registers to update
  121.     dw      06b00h  ; horz total
  122.     dw      05901h  ; horz displayed
  123.     dw      05a02h  ; start horz blanking
  124.     dw      08e03h  ; end horz blanking
  125.     dw      05e04h  ; start h sync
  126.     dw      08a05h  ; end h sync
  127.     dw      04009h  ; cell height
  128.     dw      00014h  ; turn off dword mode
  129.     dw      0e317h  ; turn on byte mode
  130.     dw      360     ; width
  131.     dw      400     ; height
  132.  
  133.  
  134. LABEL X360Y480 word
  135.     db      0e7h
  136.     db      17
  137.     dw      06b00h  ; horz total
  138.     dw      05901h  ; horz displayed
  139.     dw      05a02h  ; start horz blanking
  140.     dw      08e03h  ; end horz blanking
  141.     dw      05e04h  ; start h sync
  142.     dw      08a05h  ; end h sync
  143.     dw      00d06h  ; vertical total
  144.     dw      03e07h  ; overflow
  145.     dw      04009h  ; cell height
  146.     dw      0ea10h  ; v sync start
  147.     dw      0ac11h  ; v sync end and protect cr0-cr7
  148.     dw      0df12h  ; vertical displayed
  149.     dw      02d13h  ; offset
  150.     dw      00014h  ; turn off dword mode
  151.     dw      0e715h  ; v blank start
  152.     dw      00616h  ; v blank end
  153.     dw      0e317h  ; turn on byte mode
  154.     dw      360
  155.     dw      480
  156.  
  157. LABEL X360Y360 word
  158.     db      0e7h
  159.     db      15
  160.     dw      06b00h  ; horz total
  161.     dw      05901h  ; horz displayed
  162.     dw      05a02h  ; start horz blanking
  163.     dw      08e03h  ; end horz blanking
  164.     dw      05e04h  ; start h sync
  165.     dw      08a05h  ; end h sync
  166.     dw      04009h  ; cell height
  167.     dw      08810h  ; v sync start
  168.     dw      08511h  ; v sync end and protect cr0-cr7
  169.     dw      06712h  ; vertical displayed
  170.     dw      02d13h  ; offset
  171.     dw      00014h  ; turn off dword mode
  172.     dw      06d15h  ; v blank start
  173.     dw      0ba16h  ; v blank end
  174.     dw      0e317h  ; turn on byte mode
  175.     dw      360
  176.     dw      360
  177.  
  178. LABEL X376Y308 word
  179.     db      0e7h
  180.     db      18
  181.     dw      06e00h  ; horz total
  182.     dw      05d01h  ; horz displayed
  183.     dw      05e02h  ; start horz blanking
  184.     dw      09103h  ; end horz blanking
  185.     dw      06204h  ; start h sync
  186.     dw      08f05h  ; end h sync
  187.     dw      06206h  ; vertical total
  188.     dw      00f07h  ; overflow
  189.     dw      04009h  ;
  190.     dw      0310fh  ;
  191.     dw      03710h  ; v sync start
  192.     dw      08911h  ; v sync end and protect cr0-cr7
  193.     dw      03312h  ; vertical displayed
  194.     dw      02f13h  ; offset
  195.     dw      00014h  ; turn off dword mode
  196.     dw      03c15h  ; v blank start
  197.     dw      05c16h  ; v blank end
  198.     dw      0e317h  ; turn on byte mode
  199.     dw      376
  200.     dw      308
  201.  
  202. LABEL X376Y564 word
  203.     db      0e7h
  204.     db      18
  205.     dw      06e00h  ; horz total
  206.     dw      05d01h  ; horz displayed
  207.     dw      05e02h  ; start horz blanking
  208.     dw      09103h  ; end horz blanking
  209.     dw      06204h  ; start h sync
  210.     dw      08f05h  ; end h sync
  211.     dw      06206h  ; vertical total
  212.     dw      0f007h  ; overflow
  213.     dw      06009h  ;
  214.     dw      0310fh  ;
  215.     dw      03710h  ; v sync start
  216.     dw      08911h  ; v sync end and protect cr0-cr7
  217.     dw      03312h  ; vertical displayed
  218.     dw      02f13h  ; offset
  219.     dw      00014h  ; turn off dword mode
  220.     dw      03c15h  ; v blank start
  221.     dw      05c16h  ; v blank end
  222.     dw      0e317h  ; turn on byte mode
  223.     dw      376
  224.     dw      564
  225.  
  226. LABEL X256Y240 word
  227.     db      0e3h    ; dot clock
  228.     db      16      ; Number of CRTC Registers to update
  229.  
  230.     dw      05f00h  ; horz total
  231.     dw      03f01h  ; horz displayed
  232.     dw      04002h  ;04202h  ; start horz blanking
  233.     dw      0a003h  ;09f03h  ; end horz blanking
  234.     dw      04f04h  ; start h sync
  235.     dw      00405h  ; end h sync
  236.  
  237.     dw      00d06h  ; vertical total
  238.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  239.     dw      04109h  ; cell height (2 to double-scan)
  240.     dw      0ea10h  ; v sync start
  241.     dw      0ac11h  ; v sync end and protect cr0-cr7
  242.     dw      0df12h  ; vertical displayed
  243.     dw      0e715h  ; v blank start
  244.     dw      00616h  ; v blank end
  245.  
  246.     dw      00014h  ; turn off dword mode
  247.     dw      0e317h  ; turn on byte mode
  248.     dw      256
  249.     dw      240
  250.  
  251. LABEL X256Y70 word
  252.     db      0e3h    ; dot clock
  253.     db      16      ; Number of CRTC Registers to update
  254.  
  255.     dw      05f00h  ; horz total
  256.     dw      03f01h  ; horz displayed
  257.     dw      04002h  ;04202h  ; start horz blanking
  258.     dw      0a003h  ;09f03h  ; end horz blanking
  259.     dw      04f04h  ; start h sync
  260.     dw      00405h  ; end h sync
  261.  
  262.     dw      00d06h  ; vertical total
  263.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  264.     dw      04709h  ; cell height (8 to get blocky)
  265.     dw      0ea10h  ; v sync start
  266.     dw      0ac11h  ; v sync end and protect cr0-cr7
  267.     dw      0df12h  ; vertical displayed
  268.     dw      0e715h  ; v blank start
  269.     dw      00616h  ; v blank end
  270.  
  271.     dw      00014h  ; turn off dword mode
  272.     dw      0e317h  ; turn on byte mode
  273.     dw      256
  274.     dw      240
  275.  
  276. LABEL X256Y154 word
  277.     db      0e3h    ; dot clock
  278.     db      18      ; Number of CRTC Registers to update
  279.  
  280.     dw      05f00h  ; horz total
  281.     dw      03f01h  ; horz displayed
  282.     dw      04002h  ;04202h  ; start horz blanking
  283.     dw      0a003h  ;09f03h  ; end horz blanking
  284.     dw      04f04h  ; start h sync
  285.     dw      00405h  ; end h sync
  286.  
  287.     dw      06206h  ; vertical total
  288.     dw      00f07h  ; overflow
  289.     dw      04109h  ; CELL HEIGHT
  290.     dw      0310fh  ;
  291.     dw      03710h  ; v sync start
  292.     dw      08911h  ; v sync end and protect cr0-cr7
  293.     dw      03312h  ; vertical displayed
  294.     dw      02f13h  ; offset
  295.     dw      00014h  ; turn off dword mode
  296.     dw      03c15h  ; v blank start
  297.     dw      05c16h  ; v blank end
  298.     dw      0e317h  ; turn on byte mode
  299.     dw      256
  300.     dw      308
  301.  
  302. LABEL X256Y282 word
  303.     db      0e3h    ; dot clock
  304.     db      18      ; Number of CRTC Registers to update
  305.  
  306.     dw      05f00h  ; horz total
  307.     dw      03f01h  ; horz displayed
  308.     dw      04002h  ;04202h  ; start horz blanking
  309.     dw      0a003h  ;09f03h  ; end horz blanking
  310.     dw      04f04h  ; start h sync
  311.     dw      00405h  ; end h sync
  312.  
  313.     dw      06206h  ; vertical total
  314.     dw      0f007h  ; overflow
  315.     dw      06109h  ; cell height
  316.     dw      0310fh  ;
  317.     dw      03710h  ; v sync start
  318.     dw      08911h  ; v sync end and protect cr0-cr7
  319.     dw      03312h  ; vertical displayed
  320.     dw      02f13h  ; offset
  321.     dw      00014h  ; turn off dword mode
  322.     dw      03c15h  ; v blank start
  323.     dw      05c16h  ; v blank end
  324.     dw      0e317h  ; turn on byte mode
  325.     dw      256
  326.     dw      564
  327.  
  328.  
  329. LABEL X256Y200 word
  330.     db      0e3h    ; dot clock
  331.     db      8       ; Number of CRTC Registers to update
  332.     dw      05f00h  ; horz total
  333.     dw      03f01h  ; horz displayed
  334.     dw      04002h  ; start horz blanking
  335.     dw      0a003h  ; end horz blanking
  336.     dw      04f04h  ; start h sync
  337.     dw      00405h  ; end h sync
  338.     dw      00014h  ; turn off dword mode
  339.     dw      0e317h  ; turn on byte mode
  340.     dw      256
  341.     dw      200
  342.  
  343. LAST_X_MODE        =     17
  344.  
  345. LABEL ModeTable word    ; Mode X tweak table
  346.     dw      offset X320Y200
  347.     dw      offset X320Y240
  348.     dw      offset X360Y200
  349.     dw      offset X360Y240
  350.     dw      offset X376Y282
  351.     dw      offset X320Y400
  352.     dw      offset X320Y480
  353.     dw      offset X360Y400
  354.     dw      offset X360Y480
  355.     dw      offset X360Y360
  356.     dw      offset X376Y308
  357.     dw      offset X376Y564
  358.     dw      offset X256Y240
  359.     dw      offset X256Y200
  360.     dw      offset X320Y200s
  361.     dw      offset X256Y154
  362.     dw      offset X256Y282
  363.     dw      offset X256Y70
  364.  
  365. M320x200x256 =0     ;constants for easy calling
  366. M320x240x256 =1
  367. M360x200x256 =2
  368. M360x240x256 =3
  369. M376x282x256 =4
  370. M320x400x256 =5
  371. M320x480x256 =6
  372. M360x400x256 =7
  373. M360x480x256 =8
  374. M360x360x256 =9
  375. M376x308x256 =10
  376. M376x564x256 =11
  377. M256x240x256 =12    ;GREAT modes - ypos is upper byte, xpos is lower
  378. M256x200x256 =13
  379. M320x200x256s=14
  380. M256x154x256 =15
  381. M256x282x256 =16
  382. M256x70x256 =17
  383.  
  384. InputStatus1=   3dah
  385. Misc_Output =   3c2h
  386. SC_Index    =   3c4h
  387. CRTC_Index  =   3d4h
  388. Graph_Index =   3ceh
  389. Attr_Index  =   3c0h    ;don't forget to clear flipflop & set bit 5 on index
  390. PEL_Write   =   3c8h
  391. PEL_Read    =   3c7h
  392. PEL_Data    =   3c9h
  393.  
  394. VGASeg          dw  0A000h      ;VGA refresh buffer segment
  395. ModeXWidth      dw  0           ;physical width of current mode (in pixels)
  396. ModeXHeight     dw  0           ;physical height of current mode (in pixels)
  397. _Scrw           dw  0           ;logical width of current mode (in pixels)
  398. ModeXLogWidth   dw  0           ;logical width of current mode (in bytes)
  399. _Mode           dw  0           ;Mode X video number
  400.  
  401. MACRO @SetModeX DaMode,DaWidth
  402.     mov     ax,DaMode
  403.     mov     cx,DaWidth
  404.     call    _Set_X_Mode
  405. ENDM @SetModeX
  406.  
  407. ;-----------------------------------------------------------------------
  408. ;
  409. ;   Sets mode # in AX, returns ax=0 if successful, ax=-1 if failed
  410. ;   cx= width of screen
  411. ;
  412. ; SetModeX Adapted for VLA by Draeden,
  413. ; Originally written by Themie Gouthas,
  414. ; who adapted parts from M. Abrash code.
  415. ; (Talk about code reuse!)
  416. ;------------------------------------------------------------------------
  417. PROC _Set_X_Mode NEAR
  418.     pusha
  419.     push    es ds
  420.  
  421.     cld
  422.     mov     bx,cs
  423.     mov     ds,bx
  424.     mov     es,bx
  425.  
  426.     cmp     ax,LAST_X_MODE      ; have we selected a valid mode?
  427.     jle     @@ValidMode         ; Yes !
  428.  
  429.     pop     ds es
  430.     popa
  431.     mov     ax,-1               ; idiot.
  432.     ret
  433.  
  434. @@ValidMode:
  435.     mov     [_Mode],ax
  436.     mov     [_Scrw],cx
  437.  
  438.     mov     ax,13h              ; let the BIOS set standard 256-color
  439.     int     10h                 ;  mode (320x200 linear)
  440.  
  441.     mov     dx,SC_Index
  442.     mov     ax,0604h
  443.     out     dx,ax               ; disable chain4 mode
  444.     mov     ax,0100h
  445.     out     dx,ax               ; synchronous reset while setting Misc
  446.                                 ;  Output for safety, even though clock
  447.                                 ;  unchanged
  448.     mov     bx,[_Mode]
  449.     add     bx,bx
  450.     mov     si,[bx + ModeTable]
  451.     lodsb
  452.  
  453.     or      al,al
  454.     jz      @@DontSetDot
  455.     mov     dx,Misc_Output
  456.     out     dx,al               ; select the dot clock and Horiz
  457.                                 ;  scanning rate
  458. @@DontSetDot:
  459.     mov     dx,SC_Index
  460.     mov     ax,0300h
  461.     out     dx,ax               ; undo reset (restart sequencer)
  462.  
  463.     mov     dx,CRTC_Index       ; reprogram the CRT Controller
  464.     mov     al,11h              ; VSync End reg contains register write
  465.     out     dx,al               ; protect bit
  466.     inc     dx                  ; CRT Controller Data register
  467.     in      al,dx               ; get current VSync End register setting
  468.     and     al,07fh             ; remove write protect on various
  469.     out     dx,al               ; CRTC registers
  470.     dec     dx                  ; CRT Controller Index
  471.     cld
  472.     xor     cx,cx
  473.     lodsb
  474.     mov     cl,al
  475.  
  476. @@SetCRTParmsLoop:
  477.     lodsw                       ; get the next CRT Index/Data pair
  478.     out     dx,ax               ; set the next CRT Index/Data pair
  479.     dec     cx
  480.     jne     @@SetCRTParmsLoop
  481.  
  482.     lodsw
  483.     mov     [cs:ModeXWidth],ax
  484.     lodsw
  485.     mov     [cs:ModeXHeight],ax
  486.  
  487.     mov     dx,SC_Index
  488.     mov     ax,0f02h
  489.     out     dx,ax               ; enable writes to all four planes
  490.  
  491.                                 ; now clear all display memory, 8 pixels
  492.     mov     es,[cs:VGASeg]      ; at a time
  493.     sub     di,di               ; point ES:DI to display memory
  494.     sub     ax,ax               ; clear to zero-value pixels
  495.     mov     cx,8000h            ; # of words in display memory
  496.     rep     stosw               ; clear all of display memory
  497.  
  498.     ;  Mode X is set, now set the required logical page width.
  499.  
  500.     mov     cx,[cs:_Scrw]
  501.     shr     cx,2
  502.     mov     [cs:ModeXLogWidth],cx
  503.     shr     cx,1            ;divide by 8
  504.     mov     dx,CRTC_Index
  505.     mov     al,13h
  506.     mov     ah,cl
  507.     out     dx,ax
  508.  
  509.     pop     ds es
  510.     popa
  511.     xor     ax,ax
  512.     ret
  513. ENDP _Set_X_Mode
  514.  
  515. ────────────────────────────────────────────────────────────────────────────
  516. ;*   MISC planar mode routines
  517. ────────────────────────────────────────────────────────────────────────────
  518.  
  519.     ;ah: 0000b : bit 0= plane 0, bit 1=plane 1, etc..
  520.     ;
  521.     ;DESTROYS: al, dx
  522.     ;
  523. MACRO  @Set_Write_Plane
  524.     mov     dx,SC_Index
  525.     mov     al,2
  526.     and     ah,1111b
  527.     out     dx,ax
  528. ENDM   @Set_Write_Plane
  529.  
  530.     ;ah: plane to latch for read (0-3)
  531.     ;
  532.     ;DESTROYS: al, dx
  533.     ;
  534. MACRO  @Set_Read_Plane
  535.     mov     dx,Graph_Index
  536.     mov     al,4
  537.     out     dx,ax
  538. ENDM   @Set_Read_Plane
  539.  
  540.     ;ah: write mode (0-3)
  541.     ;
  542.     ;DESTROYS: ax, dx
  543.     ;
  544. MACRO @Set_Write_Mode
  545.     mov     dx,Graph_Index
  546.     mov     al,5
  547.     out     dx,al
  548.     inc     dx
  549.     in      al,dx
  550.     and     al,11111100b    ;clear out write mode bits
  551.     and     ah,00000011b
  552.     or      al,ah
  553.     out     dx,al
  554. ENDM  @Set_Write_Mode
  555.  
  556.     ;ah: Read mode (0-1)
  557.     ;
  558.     ;DESTROYS: ax, dx
  559.     ;
  560. MACRO @Set_Read_Mode
  561.     mov     dx,Graph_Index
  562.     mov     al,5
  563.     out     dx,al
  564.     inc     dx
  565.     in      al,dx
  566.     and     al,11110111b    ;clear out write mode bits
  567.     shl     ah,3            ;move bit to correct position
  568.     and     ah,00001000b
  569.     or      al,ah
  570.     out     dx,al
  571. ENDM  @Set_Read_Mode
  572.  
  573.     ;bx: starting offset
  574.     ;
  575.     ;DESTROYS: ax, dx
  576.     ;
  577. MACRO @Set_Start_Offset
  578.     mov     dx,CRTC_Index
  579.     mov     al,0ch
  580.     mov     ah,bh       ;write the HIGH byte
  581.     out     dx,ax
  582.     inc     al
  583.     mov     ah,bl       ;write the LOW byte
  584.     out     dx,ax
  585. ENDM  @Set_Start_Offset
  586.  
  587.     ;ah = pelpan value
  588.     ;
  589.     ;DESTROYS: ax, dx
  590.     ;
  591. MACRO @Set_HPP
  592.     mov     dx,InputStatus1
  593.     in      al,dx           ;dummy input
  594.     mov     dx,Attr_Index
  595.     mov     al,33h
  596.     out     dx,al
  597.     mov     al,ah
  598.     out     dx,al
  599. ENDM
  600.  
  601.     ;DESTROYS: ax, dx   - sets pixel pan compatibility
  602.     ;
  603. MACRO @Set_PPC
  604.     mov     dx,InputStatus1
  605.     in      al,dx           ;dummy input
  606.     mov     dx,Attr_Index
  607.     mov     al,30h
  608.     out     dx,al
  609.     inc     dx
  610.     in      al,dx
  611.     dec     dx
  612.     or      al,00100000b
  613.     out     dx,al
  614. ENDM
  615.  
  616.     ;bx: scanline to set split screen at
  617.     ;
  618.     ;DESTROYS: ax, dx
  619.     ;
  620. MACRO @Set_Split
  621.     mov     al,18h
  622.     mov     ah,bl
  623.     mov     dx,CRTC_Index
  624.     out     dx,ax       ;set bits 0-7
  625.  
  626.     mov     al,09h
  627.     out     dx,al
  628.     inc     dx
  629.     in      al,dx
  630.     mov     ah,bh
  631.     and     ah,00000010b
  632.     shl     ah,5
  633.     and     al,10111111b
  634.     or      al,ah
  635.     out     dx,al       ;set bit 9
  636.  
  637.     dec     dx
  638.     mov     al,07h
  639.     out     dx,al
  640.     inc     dx
  641.     in      al,dx
  642.     and     al,11101111b
  643.     mov     ah,bh
  644.     and     ah,00000001b
  645.     shl     ah,4
  646.     or      al,ah
  647.     out     dx,al       ;set bit 8
  648. ENDM @Set_Split
  649.  
  650. MACRO @FullVertWait
  651.  LOCAL @@VR, @@NVR
  652.     mov     dx,InputStatus1
  653. @@VR:
  654.     in      al,dx
  655.     test    al,8
  656.     jz      @@VR                    ;wait until Verticle Retrace starts
  657. @@NVR:
  658.     in      al,dx
  659.     test    al,8
  660.     jnz     @@NVR                   ;wait until Verticle Retrace Ends
  661. ENDM @FullVertWait
  662.  
  663. MACRO @WaitVert
  664.  LOCAL @@VR
  665.     mov     dx,InputStatus1
  666. @@VR:
  667.     in      al,dx
  668.     test    al,8
  669.     jz      @@VR                    ;wait until Verticle Retrace starts
  670. ENDM  @WaitVert
  671.  
  672. MACRO @WaitVertEnd
  673.   LOCAL @@NVR
  674.     mov     dx,InputStatus1
  675. @@NVR:
  676.     in      al,dx
  677.     test    al,8
  678.     jnz     @@NVR                   ;wait until Verticle Retrace Ends
  679. ENDM  @WaitVertEnd
  680.  
  681.     ;si = offset to palette
  682.     ;cx = number of colors to write
  683.     ;al = starting palette register
  684.     ;
  685.     ;DESTROYS: dx,si,cx
  686.     ;
  687. MACRO @WritePalette
  688.     mov     dx,cx
  689.     add     cx,cx
  690.     add     cx,dx
  691.     mov     dx,03c8h
  692.     out     dx,al
  693.     inc     dx
  694.     cld
  695.     rep outsb
  696. ENDM @WritePalette
  697.  
  698.     ;Changes the mode back to ModeX after a ResetLinear was called
  699. MACRO @ResetModeX
  700.     mov     dx,SC_Index
  701.     mov     ax,0604h
  702.     out     dx,ax               ; disable chain4 mode
  703.  
  704.     mov     dx,CRTC_Index
  705.     mov     ax,00014h           ; turn off dword mode
  706.     out     dx,ax
  707.     mov     ax,0e317h           ; turn on byte mode
  708.     out     dx,ax
  709. ENDM
  710.  
  711.     ;changes from ModeX to normal linear mode
  712.     ; only will work with an 320x200 screen w/ screenwidth of 80 bytes
  713. MACRO @ResetLinear
  714.     mov     dx,SC_Index
  715.     mov     ax,0E04h
  716.     out     dx,ax               ; enable chain4 mode
  717.  
  718.     mov     dx,CRTC_Index       ; reprogram the CRT Controller
  719.     mov     ax,04014h           ; turn on dword mode
  720.     out     dx,ax
  721.     mov     ax,0a317h           ; turn off byte mode
  722.     out     dx,ax
  723. ENDM
  724.